package com.ihrm.modules.sys.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.ihrm.common.utils.IdWorker;
import com.ihrm.modules.sys.dao.IndustryDao;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ihrm.common.utils.PageUtils;
import com.ihrm.common.utils.Query;

import com.ihrm.modules.sys.dao.CoCompanyDao;
import com.ihrm.modules.sys.entity.CoCompanyEntity;
import com.ihrm.modules.sys.service.CoCompanyService;


@Service("coCompanyService")
public class CoCompanyServiceImpl extends ServiceImpl<CoCompanyDao, CoCompanyEntity> implements CoCompanyService {

    @Autowired
    private CoCompanyDao coCompanyDao;

    @Autowired
    private IndustryDao industryDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String name = (String) params.get("name");
        IPage<CoCompanyEntity> page = new LambdaQueryChainWrapper<>(coCompanyDao)
                .like(StringUtils.isNotBlank(name), CoCompanyEntity::getName, name)
                .page(new Query<CoCompanyEntity>().getPage(params));

        PageUtils pageUtils = new PageUtils(page);
        List<CoCompanyEntity> list = (List<CoCompanyEntity>) pageUtils.getList();
        list.forEach(o -> {
            String concatName = industryDao.concatName(o.getIndustry().split("-"));
            o.setIndustryName(concatName);
        });
        return pageUtils;
    }
}
